version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.V OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

/* PRELIMINARIES */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
keep            regno year TaxPaid it_office_id ind location_code name_count_v2
bys             regno:g nreturns=_N
keep            if nreturns==10
g               logtaxpaid=log(TaxPaid)
bys             regno:egen namefreq=min(name_count_v2)
forvalues       y=2007/2015 {
g               	y_`y'=(year==`y')
}
#d					;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d					cr

/* COLUMN 1 (/* PANLE A: (FREQ<=10) */) */

local				j=1
g					treat=(namefreq<=10)
forvalues      y=2007/2015 {
g               	treat_`y'=(treat==1 & year==`y')
}
qui             areg logtaxpaid y_* treat_2*, absorb(regno) cluster(regno)
local				i=1
matrix			table[`i',`j']=_b[treat_2007]
matrix 			table[`i'+1,`j']=_se[treat_2007]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2008]
matrix 			table[`i'+1,`j']=_se[treat_2008]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2009]
matrix 			table[`i'+1,`j']=_se[treat_2009]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2010]
matrix 			table[`i'+1,`j']=_se[treat_2010]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2011]
matrix 			table[`i'+1,`j']=_se[treat_2011]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2012]
matrix 			table[`i'+1,`j']=_se[treat_2012]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2013]
matrix 			table[`i'+1,`j']=_se[treat_2013]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2014]
matrix 			table[`i'+1,`j']=_se[treat_2014]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2015]
matrix 			table[`i'+1,`j']=_se[treat_2015]
matrix			table[`i'+2,`j']=e(N)
local				j=`j'+1

/* COLUMN 2 (PANEL B: (ABOVE VS. BELOW MEDIAN)) */

drop				treat*
qui            sum namefreq, d
g              treat=namefreq<=r(p50)
forvalues      y=2007/2015 {
g              treat_`y'=(treat==1 & year==`y')
}
qui            areg logtaxpaid y_* treat_2*, absorb(regno) cluster(regno)
local				i=1
matrix			table[`i',`j']=_b[treat_2007]
matrix 			table[`i'+1,`j']=_se[treat_2007]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2008]
matrix 			table[`i'+1,`j']=_se[treat_2008]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2009]
matrix 			table[`i'+1,`j']=_se[treat_2009]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2010]
matrix 			table[`i'+1,`j']=_se[treat_2010]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2011]
matrix 			table[`i'+1,`j']=_se[treat_2011]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2012]
matrix 			table[`i'+1,`j']=_se[treat_2012]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2013]
matrix 			table[`i'+1,`j']=_se[treat_2013]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2014]
matrix 			table[`i'+1,`j']=_se[treat_2014]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2015]
matrix 			table[`i'+1,`j']=_se[treat_2015]
matrix			table[`i'+2,`j']=e(N)
local				j=`j'+1

/* COLUMN 3 (PANEL C: (BOTTOM VS. TOP QUARTILE)) */

drop				treat*
qui            sum namefreq, d
g              treat=namefreq<=r(p25)
drop           if namefreq>r(p25) & namefreq<=r(p75)
forvalues      y=2007/2015 {
g              	treat_`y'=(treat==1 & year==`y')
}
qui            areg logtaxpaid y_* treat_2*, absorb(regno) cluster(regno)
local				i=1
matrix			table[`i',`j']=_b[treat_2007]
matrix 			table[`i'+1,`j']=_se[treat_2007]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2008]
matrix 			table[`i'+1,`j']=_se[treat_2008]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2009]
matrix 			table[`i'+1,`j']=_se[treat_2009]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2010]
matrix 			table[`i'+1,`j']=_se[treat_2010]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2011]
matrix 			table[`i'+1,`j']=_se[treat_2011]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2012]
matrix 			table[`i'+1,`j']=_se[treat_2012]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2013]
matrix 			table[`i'+1,`j']=_se[treat_2013]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2014]
matrix 			table[`i'+1,`j']=_se[treat_2014]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2015]
matrix 			table[`i'+1,`j']=_se[treat_2015]
matrix			table[`i'+2,`j']=e(N)
local				j=`j'+1

/* COLUMN 4 (PANEL D: (BOTTOM VS. TOP DECILE)) */

drop				treat*
qui            sum namefreq, d
g              treat=namefreq<=r(p10)
drop           if namefreq>r(p10) & namefreq<=r(p90)
forvalues      y=2007/2015 {
g              treat_`y'=(treat==1 & year==`y')
}
qui            areg logtaxpaid y_* treat_2*, absorb(regno) cluster(regno)
local				i=1
matrix			table[`i',`j']=_b[treat_2007]
matrix 			table[`i'+1,`j']=_se[treat_2007]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2008]
matrix 			table[`i'+1,`j']=_se[treat_2008]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2009]
matrix 			table[`i'+1,`j']=_se[treat_2009]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2010]
matrix 			table[`i'+1,`j']=_se[treat_2010]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2011]
matrix 			table[`i'+1,`j']=_se[treat_2011]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2012]
matrix 			table[`i'+1,`j']=_se[treat_2012]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2013]
matrix 			table[`i'+1,`j']=_se[treat_2013]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2014]
matrix 			table[`i'+1,`j']=_se[treat_2014]
local				i=`i'+2
matrix			table[`i',`j']=_b[treat_2015]
matrix 			table[`i'+1,`j']=_se[treat_2015]
matrix			table[`i'+2,`j']=e(N)

/* FORMATTING THE TABLE */ 

svmat 			table
keep				tab*
drop				table5-table12
keep				if _n<=19
g					c11=""
replace			c11="treat $\times$ 2007" in 1
replace			c11="treat $\times$ 2008" in 3
replace			c11="treat $\times$ 2009" in 5
replace			c11="treat $\times$ 2010" in 7
replace			c11="treat $\times$ 2011" in 9
replace			c11="treat $\times$ 2012" in 11
replace			c11="treat $\times$ 2013" in 13
replace			c11="treat $\times$ 2014" in 15
replace			c11="treat $\times$ 2015" in 17
replace			c11="Observations" in 19
forvalues 		c=1/4 {
g					c`c'=string(table`c',"%9.3f")
}
foreach			r in 2 4 6 8 10 12 14 16 18 {
forvalues		c=1/4 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/4 {
replace			c`c'=string(table`c',"%15.0fc") in 19
}
forvalues		s=1/15 {
g					s`s'="&"
}
g					l="\\"
order				c11 s1 c1 s2 s3 c2 s4 s5 c3 s6 s7 c4 l
browse			c11 s1 c1 s2 s3 c2 s4 s5 c3 s6 s7 c4 l


